package com.xbongbong.saas.help;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.ProductFieldPojo;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.redis.RedisPrefixConstant;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

@Component
public class AccuryHelp {

    @Resource
    private PaasRedisHelper paasRedisHelper;

    /**
     * @Author: wujian
     * @Description: 处理期初关联产品数量精度
     * @Date: 下午7:17 2021/4/15
     * @Param: [corpid, item]
     * @return: void
     **/
    public void setAccuracy(String corpid, FieldAttrEntity item){
        String stockValue = paasRedisHelper.getValue(RedisPrefixConstant.PRODUCT_STOCK, corpid);
        if (Objects.nonNull(stockValue)){
            ProductFieldPojo stockField = JSONObject.parseObject(stockValue, ProductFieldPojo.class);
            item.setAccuracy(stockField.getAccuracy());
        }
    }
}
